{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "1f9dbbc0",
   "metadata": {},
   "source": [
    "### 上周回顾"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5a175243",
   "metadata": {},
   "source": [
    "* python运行hello world+观察标准库"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8eb85da8",
   "metadata": {},
   "source": [
    "### 本周学习内容"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6bf1e72b",
   "metadata": {},
   "source": [
    "#### 1.[github education packages](https://education.github.com/pack) \n",
    "* 注册学生账号，获取pyhton激活邮箱，为下周可以使用pycharm做准备\n",
    "#### 2.pycharm下载官网安装和jupyter notebook的安装学习\n",
    "* 注意事项：下载专业版\n",
    "#### 3.主要学习了jupyter notebook的使用\n",
    "* [官网](https://jupyter.org/)可以尝试体验及对jupyter有具体介绍\n",
    "* 如何在自己电脑打开jupyter notebook（cmd中直接执行jupyter notebook）\n",
    "* jupyter notebook可以做代码的系统管理，学到了每周如何整理自己的学习内容"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5cac594a",
   "metadata": {},
   "source": [
    "#### 4.快速开始（python项目一，奇数中选择指定的时间minute）\n",
    "* 变量？\n",
    "* if else?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "a76eceb9",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 准备工作（准备要用到的模块和函数）\n",
    "from datetime import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c5a2a2e2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2021, 10, 10, 10, 46, 55, 78990)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datetime.today()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "ffe9b509",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Not an odd minute.\n"
     ]
    }
   ],
   "source": [
    "# 课本代码（项目一，从奇数中选择对应的时间节点）\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "right_this_minute = datetime.today().minute\n",
    "\n",
    "if right_this_minute in odds:\n",
    "    print(\"时间是奇数，时间在odds的数据中\")\n",
    "else:\n",
    "    print(\"Not an odd minute.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ddf1f8c1",
   "metadata": {},
   "source": [
    "#### 5.变量+数值(int,float)&字符串(str)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "ae4bda65",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'wait_time'"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "##### 5.1 数字\n",
    "\"wait_time = random.randint(1,60)\"\n",
    "\"wait_time\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "13345151",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2 + 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "2ea56699",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5.0"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(50-5*6)/4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "d7fd3b01",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "12b18318",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesnt't\""
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'doesnt\\'t'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "dfa0d5a2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'word'"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "##### 5.2 字符串\n",
    "\"word = bottles\"\n",
    "\"word\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7d947c7b",
   "metadata": {},
   "source": [
    "##### 5.3 对象\n",
    " 在python中，一切都是对象。数字、字符串、函数、模块，所有一切都是对象。其直接结果是所有对象都可以赋给变值。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "5268cea0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Zhichao Zhichao\n",
      "Han-Teng Zhichao\n"
     ]
    }
   ],
   "source": [
    "#### 变量案例\n",
    "name = \"Zhichao\"\n",
    "\n",
    "name2 = name\n",
    "\n",
    "print(name,name2)\n",
    "\n",
    "name = \"Han-Teng\"\n",
    "\n",
    "print(name,name2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "84d7b5c8",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Not an odd minute.\n"
     ]
    },
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'today'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-10-16e4a2856cc6>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     11\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     12\u001b[0m \u001b[1;31m##### \"elif\"语句，如果有多个需要检查的条件要作为一个if语句的一部分时，会被使用。\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 13\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mtoday\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mtoday\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     14\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mtoday\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m'Saturday'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     15\u001b[0m     \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'Party!'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'today'"
     ]
    }
   ],
   "source": [
    "#### 6.if&else\n",
    "from datetime import datetime\n",
    "\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "right_this_second = datetime.today().second\n",
    "if right_this_second in odds: ####此“if”语句结果为“true\"或“false”\n",
    "    print(\"This minute seems a little odd.\")###这是一个代码块（是缩进的）\n",
    "else:#####“else”语句，指示当对应的“if”语句返回一个false值时要执行的代码块\n",
    "    print(\"Not an odd minute.\")###这也是一个代码块（是缩进的）\n",
    "    \n",
    "##### \"elif\"语句，如果有多个需要检查的条件要作为一个if语句的一部分时，会被使用。\n",
    "\n",
    "if today == 'Saturday':\n",
    "    print('Party!')\n",
    "elif today == 'Sunday':\n",
    "    print('Recover.')\n",
    "else:\n",
    "    print(\"Work,work,work.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "3c562197",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "#### 7.for+range\n",
    "#### 7.1for的三种典型用法\n",
    "##### 7.1.1 用例1:循环次数已知时使用for\n",
    "for i in [1,2,3]:###用“i”作为循环迭代变量\n",
    "    print(i)###这是一个代码组 需要按两次回车才能执行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "6ec99a01",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "H\n",
      "i\n",
      "!\n"
     ]
    }
   ],
   "source": [
    "##### 7.1.2 用例2：序列是一个有序的对象集合\n",
    "for ch in \"Hi!\":\n",
    "    print(ch)###字符串迭代处理 一次处理一个字符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "fa36a37c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Head First Rocks!\n",
      "Head First Rocks!\n",
      "Head First Rocks!\n",
      "Head First Rocks!\n",
      "Head First Rocks!\n"
     ]
    }
   ],
   "source": [
    "##### 7.1.3 用例3：迭代指定的次数\n",
    "for num in range(5):###请求包含五个数的范围 因此迭代五次\n",
    "    print('Head First Rocks!')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "28f378c4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 5)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#### 7.2 range试验\n",
    "range(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "cfcf3d65",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3, 4]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(5))##### 将“range”的输出输入到“list”中会生成一个列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "69dd3dab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[5, 6, 7, 8, 9]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(5,10))##### 可以调整“range”的START和STOP值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "fefa2913",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 2, 4, 6, 8]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(0,10,2))##### 可以调整STEP值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "21187dc1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 8, 6, 4, 2]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(10,0,-2))##### 通过设置STEP为负值来调整范围方向"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "512bddb8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(10,0,2))##### 如果START值大于STOP值，而STEP为正值，将得不到什么结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "3ab934c1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[99,\n",
       " 98,\n",
       " 97,\n",
       " 96,\n",
       " 95,\n",
       " 94,\n",
       " 93,\n",
       " 92,\n",
       " 91,\n",
       " 90,\n",
       " 89,\n",
       " 88,\n",
       " 87,\n",
       " 86,\n",
       " 85,\n",
       " 84,\n",
       " 83,\n",
       " 82,\n",
       " 81,\n",
       " 80,\n",
       " 79,\n",
       " 78,\n",
       " 77,\n",
       " 76,\n",
       " 75,\n",
       " 74,\n",
       " 73,\n",
       " 72,\n",
       " 71,\n",
       " 70,\n",
       " 69,\n",
       " 68,\n",
       " 67,\n",
       " 66,\n",
       " 65,\n",
       " 64,\n",
       " 63,\n",
       " 62,\n",
       " 61,\n",
       " 60,\n",
       " 59,\n",
       " 58,\n",
       " 57,\n",
       " 56,\n",
       " 55,\n",
       " 54,\n",
       " 53,\n",
       " 52,\n",
       " 51,\n",
       " 50,\n",
       " 49,\n",
       " 48,\n",
       " 47,\n",
       " 46,\n",
       " 45,\n",
       " 44,\n",
       " 43,\n",
       " 42,\n",
       " 41,\n",
       " 40,\n",
       " 39,\n",
       " 38,\n",
       " 37,\n",
       " 36,\n",
       " 35,\n",
       " 34,\n",
       " 33,\n",
       " 32,\n",
       " 31,\n",
       " 30,\n",
       " 29,\n",
       " 28,\n",
       " 27,\n",
       " 26,\n",
       " 25,\n",
       " 24,\n",
       " 23,\n",
       " 22,\n",
       " 21,\n",
       " 20,\n",
       " 19,\n",
       " 18,\n",
       " 17,\n",
       " 16,\n",
       " 15,\n",
       " 14,\n",
       " 13,\n",
       " 12,\n",
       " 11,\n",
       " 10,\n",
       " 9,\n",
       " 8,\n",
       " 7,\n",
       " 6,\n",
       " 5,\n",
       " 4,\n",
       " 3,\n",
       " 2,\n",
       " 1]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(99,0,-1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "eb3d8a50",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.5973473457483807\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "#### 8.random板块\n",
    "import random\n",
    "print(random.random())\n",
    "#random.random()用于生成一个0到1的随机符点数: 0 <= n < 1.0\n",
    "print (random.randint(1,7)) \n",
    "#random.randint()的函数原型为：random.randint(a, b)，用于生成一个指定范围内的整数。\n",
    "# 其中参数a是下限，参数b是上限，生成的随机数n: a <= n <= b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cc5c5456",
   "metadata": {},
   "outputs": [],
   "source": [
    "#### 9.beersong代码\n",
    "word = \"bottles\"\n",
    "for beer_num in range(99,0,-1):\n",
    "    print(beer_num,word,\"of beer on the wall.\")\n",
    "    print(beer_num,word,\"of beer.\")\n",
    "    print(\"Take one down.\")\n",
    "    print(\"Pass it around.\")\n",
    "    if beer_num == 1:\n",
    "        print(\"No more bottles of beer on the wall.\")\n",
    "    else:\n",
    "        new_num = beer_num - 1\n",
    "        if new_num == 1:\n",
    "            word = \"bottle\"\n",
    "        print(new_num,word,\"of beer on the wall.\")\n",
    "        print()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
